# -*- coding: utf-8 -*-
#error_code.py

import logging

class Error(Exception):
    code    =0
    msg =None
    note    =None
    level   =None
    name    =""
    
    def __init__(self,note="empty"):
        Exception.__init__(self)
        self.set_note(note)
        
    def set_note(self,note):
        self.note=note
    def get_note(self):
        return self.note


    def __str__(self):
        return "    -    CODE:%d MSG:%s NOTE:%s \n"%(self.code,self.msg,self.note)
    
    def log(self):
        if(self.level   ==  logging.DEBUG):
            logging.debug(self.__str__())

        if(self.level   ==  logging.INFO):
            logging.info(self.__str__())
            
        if(self.level   ==  logging.WARNING):
            logging.warning(self.__str__())
        
        if(self.level   ==  logging.ERROR):
            logging.error(self.__str__())
        
        if(self.level   ==  logging.CRITICAL):
            logging.critical(self.__str__())
#THREAD_NOT_EXIST=xmw.Error(code=60001,msg="Thread Not Exist!",level=xmw.ERROR_WARNING)

class OK(Error):
    code=0
    msg="OK!"
    level=logging.INFO
    name="OK"

class THREAD_NOT_EXIST(Error):
    code=60001
    msg="Thread Not Exist!"
    level=logging.WARNING
    name="THREAD_NOT_EXIST"

        
class ARGUMENT_FAULT(Error):
    code=60002
    msg="Argument Fault!"
    level=logging.ERROR
    name    ="ARGUMENT_FAULT"

class THREAD_EXIST(Error):
    code=60003
    msg="Thread already Exist!"
    level=logging.WARNING
    name="THREAD_EXIST"

class THREAD_PAGE_REFRESH(Error):
    code=60004
    msg="Refresh Thread Page List!"
    level=logging.INFO
    name="THREAD_PAGE_REFRESH"

class THREAD_ADDED(Error):
    code=60005
    msg="Thread added!"
    level=logging.INFO
    name="THREAD_ADDED"

class PAGE_EXIST(Error):
    code=60006
    msg="Page Exist!"
    level=logging.INFO
    name="PAGE_EXIST"

class NO_THREAD_REQUEST(Error):
    code=60007
    msg="There is no request to scan thread!"
    level=logging.INFO
    name="NO_THREAD_REQUEST"

class NO_POST_UPDATE_REQUEST(Error):
    code=60008
    msg="There is no request to update thread post!"
    level=logging.INFO
    name="NO_POST_UPDATE_REQUEST"  

class NEW_SCANPOST_Task(Error):
    code=60009
    msg="new task generated to scan post"
    level=logging.INFO
    name="NEW_SCANPOST_Task"  

class NO_SCANPOST_TASK(Error):
    code=60010
    msg="NO_SCANPOST_TASK wait to handle"
    level=logging.INFO
    name="NO_SCANPOST_TASK"  

class NOT_SUPPORTED_THREAD(Error):
    code=60011
    msg="This kind of thread not supported yet!"
    level=logging.INFO
    name="NOT_SUPPORTED_THREAD"      

class MISSION_ACCOMPLISHED(Error):
    code=60012
    msg="Finished scanning post for the thread!"
    level=logging.INFO
    name="MISSION_ACCOMPLISHED" 

class SCAN_ONE_PAGE(Error):
    code=60013
    msg="scanning one page post for the thread!"
    level=logging.INFO
    name="SCAN_ONE_PAGE" 

class UNSUPPORTED_MSG(Error):
    code=60014
    msg="received message unsupported!"
    level=logging.ERROR
    name="UNSUPPORTED_MSG" 

class POST_MSG_PARAM_FAULT(Error):
    code=60015
    msg="expected param not found while to build msg from post!"
    level=logging.ERROR
    name="POST_MSG_PARAM_FAULT"     

class NO_MSG_IN_QUEUE(Error):
    code=60016
    msg="there is no message to be handled!"
    level=logging.INFO
    name="NO_MSG_IN_QUEUE"     
    
class REQUESTED_PAGE_NOT_EXIST(Error):
    code=60017
    msg="REQUESTED_PAGE_NOT_EXIST!"
    level=logging.INFO
    name="REQUESTED_PAGE_NOT_EXIST" 

class NO_THREAD_TO_TRACE(Error):
    code=60018
    msg="there is no thread in bot for tracing!"
    level=logging.WARNING
    name="NO_THREAD_TO_TRACE"

class POST_NOT_EXIST(Error):
    code=60019
    msg="post not exist"
    level=logging.WARNING
    name="POST_NOT_EXIST"
                 
class OFFSET_OUT_OF_RANGE(Error):
    code=60020
    msg="required offset not scaned or not exist"
    level=logging.error
    name="OFFSET_OUT_OF_RANGE"
def main():
    e=THREAD_NOT_EXIST(note="test")
    e.log()
    print e.__class__
if __name__ == "__main__":
    main()